<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property string $name 
 * @property string $created_by 
 * @property string $receiver 
 * @property string $class 
 * @property int $deathline
 * @property int $start_submit_at 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class Event extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'event';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'deathline' => 'integer', 'start_submit_at' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function s_count()
    {
        return $this->hasOne(EventInfo::class,'event_id','id')->groupBy(['submitter_id'])->count();
    }

    /**
     * 关联事件详情
     * @return \Hyperf\Database\Model\Relations\HasMany
     */
    public function info()
    {
        return $this->hasMany(EventInfo::class, 'event_id', 'id')
            ->where('deleted_at', '=', 0)
            ->select(['id','event_name','event_id', 'submitter','file','remark','created_at']);
    }
}